﻿using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Globalization;

namespace Oya.Data
{
    public class OyaConfigurationContext
    {

        public string Xmlstoreroot
        {
            get
            {
                return mXmlstoreroot;
            }
        }
        private string mXmlstoreroot;


        //public string[] Instruments
        //{
        //    get
        //    {
        //        return mInstruments;
        //    }
        //}

        //private string[] mInstruments;



        
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="args"></param>
        public OyaConfigurationContext(NameValueCollection args)
        {
            string sDateFormat = "MM.dd.yyyy HH:mm:ss";

            mXmlstoreroot = GetRequiredArgument(args, "xmlstoreroot");


            //creates us an array of string with our 
       //     mInstruments = GetRequiredArgument(args, "Instruments").Split(',');



            

        }

        /// <summary>
        /// Get required argument from configuration file
        /// </summary>
        /// <param name="args">Configuration file key-value collection</param>
        /// <param name="sArgumentName">Argument name (key) from configuration file</param>
        /// <returns>Argument value</returns>
        private string GetRequiredArgument(NameValueCollection args, string sArgumentName)
        {
            string sArgument = args[sArgumentName];
            if (!string.IsNullOrEmpty(sArgument))
            {
                sArgument = sArgument.Trim();
            }
            if (string.IsNullOrEmpty(sArgument))
            {
                throw new Exception(string.Format("Please provide {0} in configuration file", sArgumentName));
            }
            return sArgument;
        }
    }
}
